package com.mdcorbri.helicoptobot.mediators.helicoptobot
{
	
	
	
	
	import com.mdcorbri.helicoptobot.mediators.AbstractViewMediator;
	import com.mdcorbri.helicoptobot.views.helicoptobot.HelicoptobotView;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.core.UIComponent;
	import mx.events.DynamicEvent;
	
	
	public class HelicoptobotViewMediator extends AbstractViewMediator
	{
		
		private var dynamicEvent:DynamicEvent;
		
		public function HelicoptobotViewMediator()
		{
			super();
		}
		
		
		
		/**
		 * 
		 */
		public function get view():HelicoptobotView
		{
			return this._view as HelicoptobotView;
		}
		
		override protected function setViewListeners():void
		{
			super.setViewListeners();
			
			this.view.cnvsRobotGaugeHotSpot.addEventListener(MouseEvent.CLICK, handleCnvsRobotGaugeHotSpot);
			
			this.view.cnvsRobotLeyeHotSpot.addEventListener(MouseEvent.CLICK, handleCnvsRobotLeyeHotSpot);
			
			this.view.cnvsRobotReyeHotSpot.addEventListener(MouseEvent.CLICK, handleCnvsRobotReyeHotSpot);
		}
		
		override protected function setViewDataBindings():void
		{
			super.setViewDataBindings();
		}
		
		override protected function setViewSecurity():void
		{
			super.setViewSecurity();
			
		}
		
		/** ************************************************************************
		 *                mediators
		 *  ************************************************************************/
		 
		 
		 
		 
		
		/** ************************************************************************
		 *                handlers
		 *  ************************************************************************/
		private function handleCnvsRobotGaugeHotSpot(mouseEvent:MouseEvent):void
		{
			var type:String = mouseEvent.type;
			if(type == MouseEvent.MOUSE_DOWN)
			{
				this.view.cnvsRobotGaugeHotSpot.startDrag();
			}
			else if(type == MouseEvent.MOUSE_UP)
			{
				this.view.cnvsRobotGaugeHotSpot.stopDrag();
				getPoint(this.view.cnvsRobotGaugeHotSpot);
			}
			else if(type == MouseEvent.CLICK)
			{
				dynamicEvent = new DynamicEvent("HotSpotClick");
				dynamicEvent.hotSpot = "robotGauge";
				this.eventDispatcher.dispatchEvent(dynamicEvent);
			}
		}
		
		
		private function handleCnvsRobotLeyeHotSpot(mouseEvent:MouseEvent):void
		{
			var type:String = mouseEvent.type;
			if(type == MouseEvent.MOUSE_DOWN)
			{
				this.view.cnvsRobotLeyeHotSpot.startDrag();
			}
			else if(type == MouseEvent.MOUSE_UP)
			{
				this.view.cnvsRobotLeyeHotSpot.stopDrag();
				getPoint(this.view.cnvsRobotLeyeHotSpot);
			}
			else if(type == MouseEvent.CLICK)
			{
				dynamicEvent = new DynamicEvent("HotSpotClick");
				dynamicEvent.hotSpot = "leftRobotEyeHotSpot";
				this.eventDispatcher.dispatchEvent(dynamicEvent);
			}
		}
		
		private function handleCnvsRobotReyeHotSpot(mouseEvent:MouseEvent):void
		{
			var type:String = mouseEvent.type;
			if(type == MouseEvent.MOUSE_DOWN)
			{
				this.view.cnvsRobotReyeHotSpot.startDrag();
			}
			else if(type == MouseEvent.MOUSE_UP)
			{
				this.view.cnvsRobotReyeHotSpot.stopDrag();
				getPoint(this.view.cnvsRobotReyeHotSpot);
			}
			else if(type == MouseEvent.CLICK)
			{
				dynamicEvent = new DynamicEvent("HotSpotClick");
				dynamicEvent.hotSpot = "rightRobotEyeHotSpot";
				this.eventDispatcher.dispatchEvent(dynamicEvent);
			}
		}
	
		 
		 /** ************************************************************************
		 *                utils
		 *  ************************************************************************/
		 private function getPoint(uiComponent:UIComponent):void
		 {
		 	trace(uiComponent.id + ' x="' + uiComponent.x + '" y="' + uiComponent.y + '"');
		 }
		
		
		
		/**
		 * Remove any listeners we've created.
		 */
		override protected function cleanup( event:Event ):void
		{
			super.cleanup(event);
		}

	}
}